--[[
--函数5:lua_video_need_rerender
--功能:如果state处于1生成中,且duration大于duration_limit,且create_times小于等于create_times_limit,则返回1
--如果state处于1生成中,且duration大于duration_limit,且create_times大于create_times_limit,则返回2
--其余返回0
--参数:ARGV[1]:doc_id:23
--参数:ARGV[2]:duration_limit:时间限制
--参数:ARGV[3]:current_times_limit:次数限制
--参数:ARGV[4]:current_time:次数限制
--返回: 0表示不需要处理,1需要重新渲染2放弃生成
-- ]]--

local PREFIX_DOC = "doc_id_"
local key = PREFIX_DOC..ARGV[1]
local s = redis.call("hget",key,"state")
local state = tonumber(s) or 0
local d = redis.call("hget",key,"duration")
local duration = tonumber(d) or 0
local duration_limit =tonumber(ARGV[2]) or 0
local times = redis.call("hget",key,"create_times")
local time = redis.call("hget",key,"start_time")
local start_time = tonumber(time) or 0
local crrent_time = tonumber(ARGV[4]) or 0
local d =crrent_time - start_time
local create_times = tonumber(times) or 0
local current_times_limit = tonumber(ARGV[3]) or 0
if(state==1 and d >  duration_limit and create_times <= current_times_limit)
then
    return 1
end
if(state==1 and d >  duration_limit and create_times > current_times_limit)
then
    return 2
end
return 0